-
Notifications
You must be signed in to change notification settings - Fork 17
CLOUDP-339878 - add docker caching #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
MCK 1.3.0 Release NotesNew FeaturesMulti-Architecture SupportWe've added comprehensive multi-architecture support for the kubernetes operator. This enhancement enables deployment on IBM Power (ppc64le) and IBM Z (s390x) architectures alongside
Bug Fixes
Other Changes
|
"ref": f"{cache_registry}:cache", | ||
"mode": "max", | ||
"oci-mediatypes": "true", | ||
"image-manifest": "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""
By default, the OCI media type generates an image index for the cache image. Some OCI registries, such as Amazon ECR, don't support the image index media type: application/vnd.oci.image.index.v1+json. If you export cache images to ECR, or any other registry that doesn't support image indices, set the image-manifest parameter to true to generate a single image manifest instead of an image index for the cache image:
"""
"type": "registry", | ||
"ref": f"{cache_registry}:cache", | ||
"mode": "max", | ||
"oci-mediatypes": "true", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oci is the future
cache_to = { | ||
"type": "registry", | ||
"ref": f"{cache_registry}:cache", | ||
"mode": "max", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max means we are caching all layers
|
||
DEFAULT_BUILDER_NAME = "multiarch" # Default buildx builder name | ||
|
||
|
||
def ensure_ecr_cache_repository(repository_name: str, region: str = "us-east-1"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is none - we should create the repo!
raise | ||
|
||
|
||
def build_cache_configuration(base_registry: str) -> tuple[list[Any], dict[str, str]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some gotchas:
- its one cache per image
- every cache tag has one manifest which gets overwritten
- thus, i've added a dedicated cache tag per branch but always read from master and push to master on master merges (more info here and here and a really good blog post)
""" | ||
Detect the current git branch for cache scoping. | ||
|
||
In CI environments like Evergreen, git rev-parse --abbrev-ref HEAD returns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first run (not cached)
[2025/09/01 19:58:23.476] #13 [stage-2 3/6] RUN microdnf install -y glibc-langpack-en
[2025/09/01 19:58:23.476] #13 4.815 Complete.
[2025/09/01 19:58:23.476] #13 DONE 5.2s
[2025/09/01 19:58:23.607] #14 [builder 2/11] ADD https://github.com/stedolan/jq/releases/download/jq-1.8.1/jq-linux-amd64 /usr/local/bin/jq
[2025/09/01 19:58:23.607] #14 DONE 0.3s
[2025/09/01 19:58:23.607] #15 [builder 3/11] RUN chmod +x /usr/local/bin/jq
[2025/09/01 19:58:23.607] #15 DONE 0.1s
[2025/09/01 19:58:23.607] #16 [builder 4/11] COPY go.sum go.mod /go/src/github.com/mongodb/mongodb-kubernetes/
[2025/09/01 19:58:23.794] #16 DONE 0.0s
[2025/09/01 19:58:23.794] #17 [builder 5/11] WORKDIR /go/src/github.com/mongodb/mongodb-kubernetes
[2025/09/01 19:58:23.794] #17 DONE 0.0s
[2025/09/01 19:58:23.794] #18 [builder 6/11] RUN go mod download
[2025/09/01 19:58:29.011] #18 DONE 5.2s
[2025/09/01 19:58:29.011] #19 [builder 7/11] COPY . /go/src/github.com/mongodb/mongodb-kubernetes
[2025/09/01 19:58:29.255] #19 DONE 0.2s
[2025/09/01 19:58:29.255] #20 [builder 8/11] RUN mkdir /build && if [ false = "true" ]; then echo "Building with race detector" && CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o /build/mongodb-<REDACTED:macos_notary_keyid> -buildvcs=false -race -ldflags=" -X github.com/mongodb/mongodb-kubernetes/pkg/util.OperatorVersion=68b5de77d98e1b000707f5c7 -X github.com/mongodb/mongodb-kubernetes/pkg/util.LogAutomationConfigDiff=false"; else echo "Building without race detector" && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /build/mongodb-<REDACTED:macos_notary_keyid> -buildvcs=false -ldflags="-s -w -X github.com/mongodb/mongodb-kubernetes/pkg/util.OperatorVersion=68b5de77d98e1b000707f5c7 -X github.com/mongodb/mongodb-kubernetes/pkg/util.LogAutomationConfigDiff=false"; fi
[2025/09/01 19:59:24.255] #20 0.065 Building without race detector
[2025/09/01 19:59:24.256] #20 DONE 55.0s
[2025/09/01 19:59:24.256] #21 [builder 9/11] RUN mkdir -p /data
[2025/09/01 19:59:24.256] #21 DONE 0.1s
[2025/09/01 19:59:24.256] #22 [builder 10/11] RUN cat release.json | jq -r '.supportedImages."mongodb-agent" | { "supportedImages": { "mongodb-agent": . } }' > /data/om_version_mapping.json
[2025/09/01 19:59:24.256] #22 DONE 0.1s
[2025/09/01 19:59:24.403] #23 [builder 11/11] RUN chmod +r /data/om_version_mapping.json
[2025/09/01 19:59:24.403] #23 DONE 0.1s
[2025/09/01 19:59:24.403] #24 [base 1/3] COPY --from=builder /build/mongodb-<REDACTED:macos_notary_keyid> /data/
[2025/09/01 19:59:24.563] #24 DONE 0.0s
[2025/09/01 19:59:24.563] #25 [base 2/3] COPY --from=builder /data/om_version_mapping.json /data/om_version_mapping.json
[2025/09/01 19:59:24.563] #25 DONE 0.1s
[2025/09/01 19:59:24.668] #26 [base 3/3] ADD docker/mongodb-<REDACTED:macos_notary_keyid>/licenses /data/licenses/
[2025/09/01 19:59:24.668] #26 DONE 0.0s
[2025/09/01 19:59:24.668] #27 [stage-2 4/6] COPY --from=base /data/mongodb-<REDACTED:macos_notary_keyid> /usr/local/bin/mongodb-<REDACTED:macos_notary_keyid>
[2025/09/01 19:59:24.668] #27 DONE 0.0s
[2025/09/01 19:59:24.853] #28 [stage-2 5/6] COPY --from=base /data/om_version_mapping.json /usr/local/om_version_mapping.json
[2025/09/01 19:59:24.853] #28 DONE 0.0s
[2025/09/01 19:59:24.853] #29 [stage-2 6/6] COPY --from=base /data/licenses /licenses/
[2025/09/01 19:59:24.853] #29 DONE 0.0s
[2025/09/01 19:59:26.590] #30 exporting to image
second run (cached)
[2025/09/02 10:31:02.870] #13 [builder 3/11] RUN chmod +x /usr/local/bin/jq
[2025/09/02 10:31:02.870] #13 CACHED
[2025/09/02 10:31:02.870] #14 [builder 4/11] COPY go.sum go.mod /go/src/github.com/mongodb/mongodb-kubernetes/
[2025/09/02 10:31:02.870] #14 CACHED
[2025/09/02 10:31:02.870] #15 [builder 5/11] WORKDIR /go/src/github.com/mongodb/mongodb-kubernetes
[2025/09/02 10:31:02.870] #15 CACHED
[2025/09/02 10:31:02.870] #16 [builder 2/11] ADD https://github.com/stedolan/jq/releases/download/jq-1.8.1/jq-linux-amd64 /usr/local/bin/jq
[2025/09/02 10:31:02.870] #16 CACHED
[2025/09/02 10:31:02.870] #17 [builder 6/11] RUN go mod download
[2025/09/02 10:31:03.177] #17 CACHED
[2025/09/02 10:31:03.177] #17 [builder 6/11] RUN go mod download
[2025/09/02 10:31:03.177] #17 sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0
Summary
This pull request introduces a new branch and cache scoping system for Docker BuildKit remote cache in CI and local development environments. It adds robust branch detection and cache scope generation logic, integrates these into the image build process, and provides comprehensive unit tests to ensure correctness. The main goal is to enable per-branch and per-patch caching for Docker builds, improving build performance and cache isolation.
Branch and cache scoping infrastructure:
scripts/release/branch_detection.py
with functions to detect the current git branch and generate sanitized cache scope strings for use in BuildKit caching, supporting both local development and Evergreen CI environments.Integration with image build process:
scripts/release/build/image_build_process.py
to use the new branch and cache scope utilities for configuring BuildKit cache, including logic to set up per-branch/per-patch cache repositories and read/write precedence (branch → master).Proof of Work
Checklist
skip-changelog
label if not needed